/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.me.counttimer;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView.*;
import android.app.AlertDialog ;
import android.content.Intent;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.Toast;

import com.android.MyDatabase ;

/**
 *
 * @author ksemuldie
 */
public class NewSessionActivity extends Activity {
  
  @Override
  //protected void onStart(Bundle savedInstanceState) {
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.form_session);

    //SaveSession = new Button(this) ;
    Button SaveSession = (Button) findViewById(R.id.submit);
    SaveSession.setOnClickListener(new View.OnClickListener() {
      public void onClick(View view) {
        MyDatabase db=new MyDatabase(getApplicationContext());
        db.open();  //apriamo il db

        AutoCompleteTextView newSessionNameView = (AutoCompleteTextView) findViewById(R.id.s_name);

        String newSessionText = newSessionNameView.getText().toString() ;

        db.insertSession(newSessionText) ;

        db.close() ;

        /*Intent myIntent = new Intent(view.getContext(), MainActivity.class);
        startActivity(myIntent) ;*/

        Toast.makeText(getBaseContext(),
          getString(R.string.added_session)+newSessionText,
          Toast.LENGTH_SHORT).show();

        NewSessionActivity.this.finish();
      }
    });

  }

}
